package sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Conexion implements IConexion{
        
//        private String URL = "jdbc:sqlserver://pooserver.dnsdojo.net:80;databaseName = taller_nuevo";
		//private String URL = "jdbc:sqlserver://proyectosuade.no-ip.org;databaseName = numeros_cortos_mg";
//		private String URL = "jdbc:sqlserver://proyectosuade.no-ip.org:1434;databaseName = seminario_uade";
//		private String URL = "jdbc:sqlserver://64.76.120.14:65390;databaseName = numeros_cortos_mg";
	private String URL = "jdbc:sqlserver://higgs;databaseName = numeros_cortos_mg_c_datos";
//	private String URL = "jdbc:sqlserver://64.76.120.14:65390;databaseName = numeros_cortos_mg";

	
		private String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        private String USUARIO = "sa";
        private String PASSWORD = "UADE1234";
        
        private Connection connection;
        
        
        private static Conexion iConexion;
        
        public static Conexion obtenerInstancia(){
                if(iConexion == null){
                        iConexion = new Conexion();
                }
                return iConexion;
        }
        
        private Conexion(){
                try {
                        Class.forName(DRIVER);
                        connection = DriverManager.getConnection(URL,USUARIO,PASSWORD);
                        System.out.println("se conecto a la base");
                } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        public Connection getConnection() {
                return connection;
        }

        @Override
        public ResultSet ejecutarPreparedStatement(String query) throws SQLException {

                Statement statement = connection.createStatement();
                ResultSet resultSet = statement.executeQuery(query);
                return resultSet;
        }

        @Override
        public void ejecutarSatement(String query) throws SQLException {
                Statement st;
                        st = connection.createStatement();
                        st.executeUpdate(query);
        }

		@Override
		public PreparedStatement prepareStatement(String query)
				throws SQLException {
			// TODO Auto-generated method stub
			PreparedStatement ps =  null;
			ps = connection.prepareStatement(query);
			
			return ps;
		}

}